package com.tuanzi.loan.business.repository.family.impl;

import com.tuanzi.loan.business.repository.family.custom.LoanNewCreditCardProgressRepositoryCustom;
import com.tuanzi.loan.core.repository.JOOQBaseRepository;
import com.tuanzi.loan.vo.request.family.LoanNewCreditCardProgressRequest;
import com.tuanzi.loan.vo.response.family.LoanNewCreditCardProgressResponse;
import org.jooq.impl.TableImpl;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import static com.tuanzi.loan.generated.jooq.loan.tables.LoanNewCreditCardProgress.LOAN_NEW_CREDIT_CARD_PROGRESS;

/**
 * User: liangZongXi
 * Create time: 10:33 2018/9/20
 * Description:
 */
@Repository
public class LoanNewCreditCardProgressRepositoryImpl extends JOOQBaseRepository implements LoanNewCreditCardProgressRepositoryCustom {
    @Override
    public Page<LoanNewCreditCardProgressResponse> list(LoanNewCreditCardProgressRequest searchRequest, Pageable pageable) {
        fields(LOAN_NEW_CREDIT_CARD_PROGRESS.fields());
        contains(LOAN_NEW_CREDIT_CARD_PROGRESS.BANK_NAME, searchRequest.getBankName());

        return search(pageable, record -> {
            LoanNewCreditCardProgressResponse response = new LoanNewCreditCardProgressResponse();
            response.setId(record.get(LOAN_NEW_CREDIT_CARD_PROGRESS.ID));
            response.setBankName(record.get(LOAN_NEW_CREDIT_CARD_PROGRESS.BANK_NAME));
            response.setRedirectUrl(record.get(LOAN_NEW_CREDIT_CARD_PROGRESS.REDIRECT_URL));
            response.setStatus(record.get(LOAN_NEW_CREDIT_CARD_PROGRESS.STATUS));
            response.setUpdator(record.get(LOAN_NEW_CREDIT_CARD_PROGRESS.UPDATOR));
            response.setUpdateTime(record.get(LOAN_NEW_CREDIT_CARD_PROGRESS.UPDATE_TIME));
            return response;
        });
    }

    @Override
    protected TableImpl getTable() {
        return LOAN_NEW_CREDIT_CARD_PROGRESS;
    }
}
